package com.qipay.admin.login;

import com.qipay.admin.BaseController;
import com.qipay.baas.model.Peizhi;
import com.qipay.notice.NoticeService;
import com.qipay.security.UserDetailsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * 公告类~
 */
@Controller
@RequestMapping("/notice")
public class NoticeController extends BaseController {
    @Autowired
    NoticeService noticeService;

    @GetMapping("")
    public ModelAndView find(){
        Peizhi peizhi = noticeService.getPeizhi();
        ModelAndView view = createModelAndView("peizhi");
        view.addObject("peizhi",peizhi);
        return view;
    }
    @RequestMapping(value = {"/save"}, method = RequestMethod.POST)
    public ModelAndView save(@AuthenticationPrincipal UserDetailsServiceImpl.LoginUserDetails loginUser,
                             Peizhi peizhi){
        noticeService.save(peizhi);
        peizhi = noticeService.getPeizhi();
        ModelAndView view = createModelAndView("peizhi");
        return view;
    }

}
